using Domain.Dto;
using Gmmy.DomainExtension;
using Gmmy.Utility;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Domain.Model
{
    /// <summary>
    /// 角色模块关系模型
    /// </summary>
    public class UserRole : EntityBase
    {
		#region 领域对象属性
        /// <summary>
        /// 编号
        /// </summary>
        [DisplayName(@"编号")]
        [Key]
        public Guid ID { get; set; }

        /// <summary>
        /// 用户编号
        /// </summary>
        [DisplayName(@"用户编号")]
        public Guid UserId { get; set; }

        /// <summary>
        /// 角色编号
        /// </summary>
        [DisplayName(@"角色编号")]
        public Guid RoleId { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [DisplayName(@"创建时间")]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        [DisplayName(@"逻辑删除")]
        public bool IsDeleted { get; set; }


        #endregion

		#region 领域对象行为
		public UserRole() { }//空构造函数

        /// <summary>
        /// 创建角色模块关系
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="roleId"></param>
        public UserRole(Guid userId, Guid roleId)
        {
            if (userId == Guid.Empty || roleId == Guid.Empty)
            {
                throw new CustomException("请确保用户和角色有效!");
            }
            ID = Guid.NewGuid();
            UserId = userId;
            RoleId = roleId;
            CreateTime = DateTime.Now;
            IsDeleted = false;
        }

        #endregion

    }
}